package milkyway.hightech.b2b;

import java.util.HashMap;
import java.util.Map;

import milkyway.hightech.b2b.B2B;
import milkyway.hightech.exceptions.BankNotFountException;

public class BankRegistry
{
    private static BankRegistry registry;
    Map<String, B2B> map = new HashMap<String, B2B>();

    private BankRegistry()
    {
    }

    /**
     *
     * @return
     */
    public static BankRegistry getInstance()
    {
        if (registry == null)
        {
            registry = new BankRegistry();
        }

        return registry;
    }

    /**
     *
     * @param name
     * @param bank
     */
    public void bind(String name, B2B bank)
    {
        map.put(name, bank);
    }

    /**
     *
     * @param name
     * @return
     */
    public B2B lookup(String name)
    {
        if (map.containsKey(name))
        {
            return map.get(name);
        } else
        {
            throw new BankNotFountException();
        }
    }
}